<!DOCTYPE html>
<html lang="zh-CN">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>Document</title>
	</head>

	<body>
		<!-- vue实例 -->
		<div id="app">
			<cpn :cmovies="movies" :cmessage="message"></cpn>
		</div>
		<!-- 子组件模板 -->
		<template id="cpn">
			<div>
				<ul>
					<li v-for="item in cmovies">{{item}}</li>
				</ul>
				<h2>{{cmessage}}</h2>
			</div>
		</template>
		<script src="../lib/vue.js"></script>
		<script>
			// 父传子：props
			let cpn = {
				template: "#cpn",
				// 1.数组传递
				// props: ["cmovies", "cmessage"],
				// 2.对象传递，限制类型
				// props: {
				// 	cmovies: Array,
				// 	cmessage: String,
				// },
				// 3.对象传递，默认值以及必传值
				props: {
					// 类型是Array或Object时，默认值必须是一个函数
					cmovies: {
						type: Array,
						default() {
							return [];
						}
					},
					cmessage: {
						type: String,
						default: "aaaaa",
						// 必传属性
						required: true
					}
				}
			};
			let vm = new Vue({
				el: "#app",
				data: {
					message: "hello",
					movies: ["海王", "我的王国", "我的世界"]
				},
				components: {
					cpn
				}
			});
		</script>
	</body>
</html>
